/**
 *<p>Copyright: Copyright (c) 2012</p> 
 *<p>Company: SCPII</p>
 *<p>Project:optimus-manage</p>
 *@author xiezhouyan
 *@Date 2013-4-25 下午2:53:34
 *@version 1.0
 *@description:
 */
package com.cybertron.ironhide.manage.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.cybertron.ironhide.manage.common.Constants;
import com.cybertron.ironhide.manage.common.base.BaseAction;
import com.cybertron.ironhide.manage.common.job.SiteMapGenJob;
import com.cybertron.ironhide.manage.domain.Adver;
import com.cybertron.ironhide.manage.domain.Article;
import com.cybertron.ironhide.manage.domain.Category;
import com.cybertron.ironhide.manage.domain.PopularCate;
import com.cybertron.ironhide.manage.domain.Recommend;
import com.cybertron.ironhide.manage.service.AdverService;
import com.cybertron.ironhide.manage.service.ArticleService;
import com.cybertron.ironhide.manage.service.CategoryService;
import com.cybertron.ironhide.manage.service.PopularCateService;
import com.cybertron.ironhide.manage.service.RecommendService;
import com.cybertron.ironhide.manage.util.PageUtil;

public class IndexAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8844519284908163691L;

	@Resource
	private PageUtil pageUtil;

	@Resource
	private CategoryService categoryService;

	@Resource
	private PopularCateService popularCateService;

	@Resource
	private AdverService adverService;

	@Resource
	private RecommendService recommendService;

	@Resource
	private ArticleService articleService;

	@Resource
	private SiteMapGenJob siteMapGenJob;

	@Override
	public String execute() throws Exception {
		return super.execute();
	}

	public String list() {
		return LIST;
	}

	public String page() {
		List<Recommend> recommends = recommendService.selectByIndex();
		List<Category> categories = categoryService.selectByIndex();
		List<Adver> advers = adverService.selectByIndex();
		List<PopularCate> popularCates = popularCateService.selectByIndex();
		List<Article> topArticles = articleService.selectTop(
				Constants.TOP_ARTICLE_TYPE, Constants.TOP_ARTICLE_COUNT - 1);

		List<Article> botArticles = articleService.selectTop(
				Constants.BOT_ARTICLE_TYPE, Constants.BOT_ARTICLE_COUNT);

		Map<String, Object> data = new HashMap<String, Object>();
		data.put("recommends", recommends);
		data.put("categories", categories);
		data.put("advers", advers);
		data.put("popularCates", popularCates);
		data.put("topArticles", topArticles);
		data.put("botArticles", botArticles);

		pageUtil.crateHTML(data, "index.ftl", "index.html");
		return ajaxSuccess("首页静态化成功", "index-list");
	}

	public String createSiteMap() {
		siteMapGenJob.run();
		return ajaxSuccess("生成站点地图成功", "index-list");
	}
}
